package liumengbaio.lolzhangyoubao.Activity.Adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import liumengbaio.lolzhangyoubao.Activity.Activity.SelectShowPlayActivity;
import liumengbaio.lolzhangyoubao.Activity.InFo.AllHeroInfo;
import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/8/29.
 */
public class SelectHeroAdapter extends BaseAdapter {
    private List<AllHeroInfo> allHeroInfo;
    private Context context;

    public SelectHeroAdapter(List<AllHeroInfo> allHeroInfo, Context context) {
        this.allHeroInfo = allHeroInfo;
        this.context = context;
    }

    @Override
    public int getCount() {
        return allHeroInfo.size();
    }

    @Override
    public Object getItem(int position) {
        return allHeroInfo.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewholder = null;
        if (convertView == null) {
            viewholder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_select, null);
            viewholder.nickname = (TextView) convertView.findViewById(R.id.nickname);
            viewholder.money = (TextView) convertView.findViewById(R.id.money);
            viewholder.point = (TextView) convertView.findViewById(R.id.point);
            viewholder.iconhero = (ImageView) convertView.findViewById(R.id.iconhero);
            convertView.setTag(viewholder);
        } else {
            viewholder = (ViewHolder) convertView.getTag();
        }
        convertView.findViewById(R.id.item_select).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent_item_select = new Intent(context, SelectShowPlayActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("nicker_name", allHeroInfo.get(position).getNickname());
                bundle.putString("pic_url", allHeroInfo.get(position).getPic_url());
                bundle.putString("role_id",allHeroInfo.get(position).getId());
                Log.i("001","适配器中的id为"+allHeroInfo.get(position).getId());
                intent_item_select.putExtras(bundle);
                context.startActivity(intent_item_select);
            }
        });
        AllHeroInfo info = allHeroInfo.get(position);
        viewholder.nickname.setText(info.getNickname());
        viewholder.money.setText(info.getMoney());
        viewholder.point.setText(info.getPoint());
        Picasso.with(context).load(info.getPic_url()).into(viewholder.iconhero);
        return convertView;
    }

    private class ViewHolder {
        private TextView nickname, money, point;
        private ImageView iconhero;
    }
}
